package com.smooth.site.sx.pc.job.controller.apply;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smooth.common.pc.interceptor.PcAccountContext;
import com.smooth.common.site.common.enums.SiteCodeEnums;
import com.smooth.common.site.common.excep.SiteException;
import com.smooth.common.site.common.rsp.ReturnResult;
import com.smooth.dao.gen.bean.BizCompany;
import com.smooth.dao.gen.bean.BizJobApplay;
import com.smooth.dao.gen.bean.BizStudent;
import com.smooth.site.sx.pc.job.req.apply.JobApplyQueryReq;
import com.smooth.site.sx.pc.job.req.apply.JobApplyReq;
import com.smooth.site.sx.pc.job.service.PcJobApplyService;
import com.smooth.sys.pc.vo.ListRsp;

@Controller
@RequestMapping(value = "/pc/c")
public class PcJobApplyController {
	@Autowired
	PcJobApplyService pcJobApplyService;
	@RequestMapping(value = {"stu/applyJob"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult applyJob(@Valid JobApplyReq jobApplyReq,BindingResult result,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizStudent bizStudent = (BizStudent)PcAccountContext.getObj(BizStudent.class);
		if(bizStudent==null) {
			throw new SiteException(SiteCodeEnums.AUTH_NOT_ENOUGH, "请用学生登录");
		}
		BizJobApplay bizJobApplay = pcJobApplyService.applyJob(jobApplyReq, bizStudent);
		returnResult.setData(bizJobApplay);
		
		return returnResult;
	}
	
	@RequestMapping(value = {"stu/queryApplyJobs"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult stuQueryApplyJobs(@Valid JobApplyQueryReq jobApplyQueryReq,BindingResult result,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizStudent bizStudent = (BizStudent)PcAccountContext.getObj(BizStudent.class);
		
		ListRsp<BizJobApplay> srsp = pcJobApplyService.queryStuApplyJobs(jobApplyQueryReq, bizStudent);
		returnResult.setData(srsp);
		
		return returnResult;
	}
	
	@RequestMapping(value = {"comp/optApplyJob"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult optApplyJob(@RequestParam(required=true) String jobApplyId,@RequestParam(required=true) Integer applyStatus,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizCompany bizCompany = (BizCompany)PcAccountContext.getObj(BizCompany.class);
		
		BizJobApplay bizJobApplay = pcJobApplyService.optApplyJob(jobApplyId,applyStatus, bizCompany);
		returnResult.setData(bizJobApplay);
		
		return returnResult;
	}
	
	
	@RequestMapping(value = {"comp/queryApplyJobs"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult queryApplyJobs(@Valid JobApplyQueryReq jobApplyQueryReq,BindingResult result,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizCompany bizCompany = (BizCompany)PcAccountContext.getObj(BizCompany.class);
		
		ListRsp<BizJobApplay> srsp = pcJobApplyService.queryCompApplyJobs(jobApplyQueryReq, bizCompany);
		returnResult.setData(srsp);
		
		return returnResult;
	}
}
